package org.example.controller;


import org.example.common.R;
import org.example.service.IApCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-02-04
 */
@RestController
@RequestMapping("/front")
@CrossOrigin(maxAge = 3600)
public class ApCollectController {

    @Autowired
    private IApCollectService apCollectService;

    /**
     * 收藏
     *
     * @param articleId
     * @return
     */
    @GetMapping("/collect")
    public R like(@RequestParam String articleId) {
        Long count = apCollectService.collect(articleId);
        return R.ok(count);
    }

    /**
     * 取消收藏
     *
     * @param articleId
     * @return
     */
    @GetMapping("/uncollect")
    public R unlike(@RequestParam String articleId) {
        Long count = apCollectService.uncollect(articleId);
        return R.ok(count);
    }

    /**
     * 查询自己收藏的作品
     *
     * @return
     */
    @GetMapping("collect/article")
    public R collectArticle() {
        return apCollectService.collectArticle();
    }
}
